<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style type="text/css">
        td{
            padding: 2px 0px;
            text-align: left;
            border: 1px solid #999;
        }
    </style>
        <link href="/resources/css/table.css?r=3" rel="stylesheet">
        <script src="/resources/js/jquery-1.11.1.min.js"></script>
        <script src="/resources/js/self.js"></script>
        <script type="text/javascript" src="/resources/js/md5.js"></script>
        <script type="text/javascript" src="/resources/My97DatePicker/WdatePicker.js"></script>
        <script type="text/javascript" src="/resources/js/ajaxfileupload.js"></script>
        <script type="text/javascript" src="/resources/js/Util.js?v=2"></script>
        <script type="text/javascript" src="/resources/js/idCardUtil.js"></script>
    <script src="/resources/gentelella/vendors/bootstrap/js/modal.js"></script>
    <link  href="/resources/viewer/viewer.css" rel="stylesheet">
    <script src="/resources/viewer/viewer.js"></script>
    </head>
</head>
<body>


<div>
    <table style="width:100%;">
        <tr>
            <th>

            </th>
        </tr>
        <tr>
            <td colspan="5">
                <button onclick="goBack()" class="btn btn-success" style="float:right;margin-right: 20px;">返回</button>
            </td>
            <td></td>

        </tr>
        <tr>
            <td class="name" rowspan="5" style="font-size:20px;width: 12%">
                备案单位
                <input type="hidden" id="id" name="id"
                       class="form-control form-data ">
                <input type="hidden" id="companyId" name="companyId"
                       class="form-control form-data ">
            </td>
            <td class="name">名称</td>
            <td class="value">
                <input type="text" id="name" name="name"
                       class="form-control form-data ">
            </td>
            <td class="name">
                地址
            </td>
            <td>
                <input type="text" id="address" name="address"
                       class="form-control form-data ">
            </td>
        </tr>
        <tr>
            <td class="name">
                法人代表
            </td>
            <td>
                <input type="text"  name="legalPerson"
                       class="form-control form-data ">
            </td>
            <td class="name">
                身份证号
            </td>
            <td>
                <input type="text"  name="idCard"
                       class="form-control form-data ">
            </td>
        </tr>
        <tr>
            <td class="name">
                固定电话
            </td>
            <td>
                <input type="text"  name="telephone"
                       class="form-control form-data ">
            </td>
            <td class="name">
                移动电话
            </td>
            <td>
                <input type="text"  name="mobile"
                       class="form-control form-data ">
            </td>
        </tr>
        <tr>
            <td class="name">邮箱</td>
            <td>
                <input type="text"  name="email"
                       class="form-control form-data ">
            </td>
            <td class="name">传真</td>
            <td>
                <input type="text"  name="fax"
                       class="form-control form-data ">
            </td>
        </tr>
        <tr>
            <td class="name">
                网址
            </td>
            <td colspan="3">
                <input type="text"  name="webSite"
                       class="form-control form-data ">
            </td>
        </tr>
        <tr>
            <td class="name" colspan="2">
                危化品从业类型
            </td>
            <td>
                <input type="text"  name="practiceType"
                       class="form-control form-data ">
            </td>
            <td class="name">
                安监部门颁发证书号
            </td>
            <td>
                <input type="text"  name="securityNum"
                       class="form-control form-data ">
            </td>
        </tr>
        <tr>
            <td class="name" colspan="2">
                危化品从业批准机关(市、州、地方安监部门)
            </td>
            <td>
                <input type="text"  name="securityDept"
                       class="form-control form-data ">
            </td>
            <td class="name">
                安监部门颁发证件有效期
            </td>
            <td>
                <input type="text"  name="securityTime"
                       class="form-control form-data ">
            </td>
        </tr>
        <tr>
            <td class="name" rowspan="2">
                备案登记申办人
            </td>
            <td class="name">姓名</td>
            <td>
                <input type="text"  name="applyPeople"
                       class="form-control form-data ">
            </td>
            <td class="name">身份证号</td>
            <td>
                <input type="text"  name="aIdCard"
                       class="form-control form-data ">
            </td>
        </tr>
        <tr>
            <td class="name">固定电话</td>
            <td>
                <input type="text"  name="aTelephone"
                       class="form-control form-data ">
            </td>
            <td class="name">移动电话</td>
            <td>
                <input type="text"  name="aMobile"
                       class="form-control form-data ">
            </td>
        </tr>
        <tr>
            <td class="name" colspan="2">保管人员</td>
            <td>
                <input type="text"  name="keepPeople"
                       class="form-control form-data ">
            </td>
            <td class="name">联系人及手机</td>
            <td>
                <input type="text"  name="kMobile"
                       class="form-control form-data ">
            </td>
        </tr>
        <tr>
            <td class="name" colspan="2">安全保卫负责人</td>
            <td>
                <input type="text"  name="securityPeople"
                       class="form-control form-data ">
            </td>
            <td class="name">危化品从业(人数)</td>
            <td>
                <input type="text"  name="peopleNum"
                       class="form-control form-data ">
            </td>
        </tr>
        <tr>
            <td class="name" colspan="2">环保资质有效期</td>
            <td>
                <input type="text"  name="environmentTime"
                       class="form-control form-data ">
            </td>
            <td class="name">运输车辆（合计）</td>
            <td>
                <input type="text"  name="truckNum"
                       class="form-control form-data ">
            </td>
        </tr>
        <tr>
            <td class="name" colspan="2">工商营业执照有效期</td>
            <td>
                <input type="text"  name="licenseTime"
                       class="form-control form-data ">
            </td>
            <td class="name">危化品存储地</td>
            <td>
                <input type="text"  name="area"
                       class="form-control form-data ">
            </td>
        </tr>
        <tr>
            <td class="name" colspan="2">危化品是否涉及出入境</td>
            <td>
                <input type="text"  name="transnational"
                       class="form-control form-data ">
            </td>
            <td class="name">库房有无监控、监控设备服务器品牌</td>
            <td>
                <input type="text"  name="monitorInfo"
                       class="form-control form-data ">
            </td>
        </tr>
        <tr class="product-title">
            <td colspan="2" class="name">涉及品种</td>
            <td colspan="4" class="name">年消耗量</td>
        </tr>

        <tr class="product-content-after">
            <td colspan="2" class="name" style="white-space:inherit;">
                生产、经营、存储、使用、销毁危化品的品名、数量
            </td>
            <td colspan="3">
                <input type="text"  name="pInfo"
                       class="form-control form-data ">
            </td>
        </tr>
        <tr>
            <td colspan="2" class="name">
                存储设施及安全保卫措施
            </td>
            <td colspan="3">
                <input type="text"  name="keepInfo"
                       class="form-control form-data ">
            </td>
        </tr>
        <tr>
            <td colspan="2" class="name">
                危化品用途
            </td>
            <td colspan="3">
                <input type="text"  name="pUseInfo"
                       class="form-control form-data ">
            </td>
        </tr>
        <tr>
            <td colspan="5" class="name">
                所需提供资料原件复印件
                <input type="file" id="file_input" name="file" onchange="uploadFile('file')" value="Upload your resume"
                       style="opacity: 0;width: 0px;display: none">
            </td>
        </tr>
        <tr>
            <td colspan="5">
                <div style="overflow:auto;">
                    <div  id="file_div" style="margin-top: 20px;" >
                    </div>
                </div>
            </td>
        </tr>
        <tr>
            <td colspan="5">
                <!--<button onclick="goBack()" class="btn btn-success">返回</button>-->
                <button type="button" onclick="openAuditDialog('auditSuccess')" class="btn btn-success">审核通过</button>
               <button type="button" onclick="openAuditDialog('auditFail')" class="btn btn-success">审核不通过</button>
                    </td>
                    <td></td>

                </tr>

            </table>
        </div>

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title" id="myModalLabel">
                    审核
                </h4>
            </div>
            <div class="modal-body">
                <!--<div>-->
                <!--同意:<input type="radio" name="auditStatus" value="auditSuccess">-->
                <!--拒绝:<input type="radio" name="auditStatus" value="auditFail">-->
                <!--</div>-->
                <div>
                    <textarea  rows="5" style="width:100%;" id="auditResult"></textarea>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary" onclick="auditCompany()">
                    确定
                </button>
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭
                </button>

            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>
        </body>
        <script type="application/javascript">
            $(function () {
                setTitle("基本信息>企业信息>企业备案");
                initData();
                $("[data-type='idCard']").blur(function () {
                    /*debugger*/
                    var idCard = $(this).val();
                    if(!IdentityCodeValid(idCard)){
                        /*$(this).focus();*/
                        $(this).val("");
                        $(this).attr("placeholder","身份证错误");
                    }else if(typeof($(this).attr("for-age"))!=="undefined"){
                        var ageId = $(this).attr('for-age');
                        var age=  GetAge(idCard);
                        $("#"+ageId).val(age);
                    }
                })


            });
            var _auditStatus = '';
            function openAuditDialog(_f) {
                var data = getData();
                var companyId = data.companyId;
                if(isNullOrUndefined(companyId)){
                    alert("请选择要修改的数据,并且只能选择一条");
                    return;
                }
                // $('input[type=radio][name="auditStatus"]:checked').prop("checked", false);
                _auditStatus = _f;
                $("#auditResult").html("");
                $('#myModal').modal('show');
            }
            function auditCompany() {
                var data = getData();
                var companyId = data.companyId;
                var auditStatus = _auditStatus;
                if(isNullOrUndefined(auditStatus)){
                    alert("请选择是否审批通过！");
                    return;
                }
                var auditResult = $("#auditResult").val();
                var url = "/admin/company/audit.do";
                var type = data.data_type;
                if(type == 'buy'){
                    url = "/admin/buyCompany/audit.do"
                }else if(type == 'trans'){
                    url = "/admin/transportCompany/audit.do"
                }
                $.ajax({
                    url: url + "?_t=" + new Date().getTime(),
                    data: {"companyId":companyId,"auditStatus":auditStatus} ,
                    type:'post',
                    dataType:"json",  //xml  html   script  jsonp
                    success:function(result){
                        $('#myModal').modal('hide');
                        goBack();
                        // searchData();
                    }
                });
            }
            function initData(){
                var data = getData();
                var companyId = data.companyId;
                $("input[name='companyId']").val(companyId);
                $.ajax({
                    url:"/admin/companyRegister/find.do",
                    data:{'companyId':companyId},
                    type:'post',
                    dataType:'json',
                    success:function(data){
                        console.log(data);
                        if(data.success){
                            initPageDate(data.data, '.form-data');
                            addFileInfoToTable(data.data.fileInfoList,'file');
                            var productJson = data.data.productJson;
                            if(!isNullOrUndefined(productJson)){
                                var products = JSON.parse(productJson);
                                var html = "";
                                $(".product-content").remove();
                                $(products).each(function (index,item) {
                                    var productName =  item.product;
                                    var waste = item.waste;
                                    html = html+ "<tr class='product-content'>   "+
                                        " <td colspan='2'><input type='text'  class='product' value='"+productName+"' class='form-control form-data '></td>"+
                                        " <td colspan='4'><input type='text' class='waste'  value='"+waste+"' class='form-control form-data '></td>"+
                                        "</tr>";
                                });

                                $(html).insertBefore(".product-content-after");
                            }
                        }
                    }
                });
            }
            function uploadFile(fileType) {
                $.ajaxFileUpload({
                    url: "/file/uploadFile.do?_t=" + new Date().getTime(),            //需要链接到服务器地址
                    secureuri: false,//是否启用安全提交，默认为false
                    fileElementId: fileType+'_input',                        //文件选择框的id属性
                    dataType: 'text',                                     //服务器返回的格式，可以是json, xml
                    success: function (data, status) {//服务器成功响应处理函数
                        var rpeObj = $.parseJSON(data);
                        var fileInfoList = rpeObj.data;
                        addFileInfoToTable(fileInfoList,fileType);

                    }
                });
            }
            function addFileInfoToTable(fileInfoList,fileType){
                $(fileInfoList).each(function(index,file){
                    var fileHtml = "<div  style='border-radius: 2px; width:32%;height:100px;float: left; border: 2px #ffffff solid;'>"+

                        "<div align='center' style='height:80px;margin-bottom: 0px;'>"+
                        "<div align='center' onclick='downLoadFile(\""+file.path+"\",\""+file.name+"\")' ><input type='hidden' name='"+fileType+"_id' value='"+file.id+"'>"+file.name+"</div>"+

                        "<button  style='margin-left: 20px;' " +
                        "onclick='downLoadFile(\""+file.path+"\",\""+file.name+"\")' " +
                        "name='download' extendData='"+file.id+"'class='btn btn-primary'>下载</button>"+
                    "</div>";
                    $(fileHtml).appendTo($("#"+fileType+"_div"));

                });
                $('.image').viewer();
                $("button[name='delete']").unbind('click');
                $("button[name='delete']").click(function(){
                    var id = $(this).attr("extendData");
                    $.ajax({
                        type: "POST",
                        url: "/file/delete.do?_t=" + new Date().getTime(),
                        data: "fileId=" + id,

                        success: function (result) {
                            alert("删除成功");
                        },

                        error: function (XMLHttpRequest, textStatus, thrownError) {
                            /* alert("系统异常");*/
                        }
                    });
                    $(this).parent().parent().remove();
                });
            }
            //获取要展示的图片
            function getFileShowUrl(url){
                var extStart=url.lastIndexOf(".");
                var ext=url.substring(extStart,url.length).toUpperCase();
                if(ext!=".BMP"&&ext!=".PNG"&&ext!=".GIF"&&ext!=".JPG"&&ext!=".JPEG"){
                    return "/resources/images/timg.jpg";
                }else{
                    return url;
                }
            }
            function goBack() {
                var data = getData();
                goto(data.back_url,data);
            }
            function downLoadFile(url,name) {
                var $a = $("<a></a>").attr("href", url).attr("download", name);
                $a[0].click();
            }
        </script>
        </html>